package com.kaishengit.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import com.kaishengit.entity.Goal;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;
public class GoalDao {
	private DBHelp<Goal> db=new DBHelp<Goal>();
	public List<Goal> findByProjectId(String ProjectId){
		final String sql="select id,`name`,`desc`,createtime, t_project_id from t_goal where t_project_id =?";
		return db.executeQueryForList(sql,new GoalRowmapper(), ProjectId);
	}
	public void save(Goal goal){
		final String sql="INSERT INTO t_goal(id,`name`,`desc`,createtime,t_project_id)VALUES(?,?,?,?,?)";
		db.executeSQL(sql,goal.getId(),goal.getName(),goal.getDesc(),goal.getCreatetime(),goal.getProjectid());
	}
	public void del(String goalid){
		String sql=" DELETE  FROM t_goal WHERE id= ? ";
		db.executeSQL(sql, goalid);
	}
	
	
	public Goal findById(String goalId){
		final String sql="SELECT id,`name`,`desc`,createtime,t_project_id FROM t_goal WHERE id=?";
		return db.executeQueryForObject(sql, new GoalRowmapper(), goalId);
		
		
	}
	public class GoalRowmapper implements RowMapper<Goal> {
		public Goal mapperRow(ResultSet rs) throws SQLException {
			 Goal goal=new Goal();
			 goal.setId(rs.getString("id"));
			 goal.setName(rs.getString("name"));
			 goal.setDesc(rs.getString("desc"));
		
			 goal.setProjectid(rs.getString("t_project_id"));
			 
			   
				
				
		
			return goal;
		}
		
	}
	
	
}
